
package com.alex.web.controller.member;

import com.alex.web.annotation.ExceptionFeedback;
import com.alex.web.bean.CommonResult;
import com.alex.web.bean.member.MpingtHyxx;
import com.alex.web.controller.base.BaseController;
import com.alex.web.db.domain.PageControl;
import com.alex.web.db.domain.PageInfo;
//import com.alex.web.log.MISILogger;
//import com.alex.web.log.MISILoggerFactory;
import com.alex.web.service.MpingtHyxxService;
import com.alex.common.MD5Util;
import com.alex.common.SHA1Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;

/**
 * 平台会员信息表
 * @author 密思软件
 * @date 2018-5-3 16:37:49
 */
@Controller
@RequestMapping(value = "/member/mpingtHyxx")
public class MpingtHyxxController extends BaseController {

//	private static final MISILogger logger = MISILoggerFactory.getLogger(MpingtHyxxController.class);

    @Autowired
    private MpingtHyxxService mpingtHyxxService;
	/**
	 * 跳转到列表页面
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "查询平台会员信息表列表异常")		//定义异常提示消息
	@RequestMapping("/")
	public String index(Model model){
		return getPage(model,1);
		}



	/**
	 * 跳转到指定页面
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "平台会员信息表列表分页查询异常")		//定义异常提示消息
	@RequestMapping("/page")
	public String getPage(Model model, int page){
		MpingtHyxx entity = new MpingtHyxx();
		PageInfo info = new PageInfo(page>0?page-1:0);
		PageControl<MpingtHyxx> control = mpingtHyxxService.page(entity,info,null,null);
		model.addAttribute("page",control);
		return "member/mpingtHyxx/list";
	}
	/**
	 * 根据id 查找
	 * @param id
	 * @return son数据
	 */
	@ExceptionFeedback(errorMsg = "根据id查找平台会员信息表异常")		//定义异常提示消息
	@RequestMapping("/get")
	@ResponseBody
	public CommonResult getMpingtHyxx(@RequestParam(name = "id", required = true)Integer id){
		if (id > 0){
			MpingtHyxx entity =  mpingtHyxxService.find(id);
			return CommonResult.successResult(entity);
		}else{
			return CommonResult.exceptionResult("无法解析传入对象！");
		}
	}

	/**
	 * 提交新增请求
	 * @param entity
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "新增平台会员信息表异常")		//定义异常提示消息
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	@ResponseBody
	public CommonResult addMpingtHyxx(MpingtHyxx entity, Model model) throws SQLException {
		if (entity!=null){
			int nun=0;
//			Date dqsj = entity.getDaoqsj();
			entity.setMim(MD5Util.getMisi32Code(SHA1Utils.hex_sha1(entity.getMim())));
			nun = mpingtHyxxService.insertMpingtHyxx(entity,"");
			if (nun == 0) {
				return CommonResult.exceptionResult("数据更新失败。");
			}
			if (nun == -1){ return CommonResult.exceptionResult("会员号已存在。"); }
			return CommonResult.successResult("更新成功！");
		}else {
			return CommonResult.exceptionResult("无法解析传入对象！");
		}
	}
	/**
	 * 提交修改请求
	 * @param entity
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "修改平台会员信息表异常")		//定义异常提示消息
	@RequestMapping(value = "/edit",method = RequestMethod.POST)
	@ResponseBody
	public CommonResult editMpingtHyxx(MpingtHyxx entity,Model model){
		if (entity!=null){
			int nun = 0;
			nun = mpingtHyxxService.updateMpingtHyxx(entity);
			if (nun == 0) {
				return CommonResult.exceptionResult("数据更新失败。");
			}
			if (nun == -1) {
				return CommonResult.exceptionResult("会员号已存在。");
			}
			return CommonResult.successResult("更新成功！");
		}else {
			return CommonResult.exceptionResult("无法解析传入对象！");
		}
	}
	/**
	 * 根据id删除
	 * @param id
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "删除平台会员信息表异常")		//定义异常提示消息
	@RequestMapping("/del")
	@ResponseBody
	public CommonResult delMpingtHyxx(@RequestParam(name = "id", required = true)int id){
		int nun = 0;

		nun = mpingtHyxxService.delete(id);
		if (nun <= 0) {
			return CommonResult.exceptionResult("删除失败。");
		}
		return CommonResult.successResult("删除成功！");
	}

	/**
	 * 根据id作废或恢复，数据库里要存在有效标志。
	 * @param id
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "作废平台会员信息表异常")		//定义异常提示消息
	@RequestMapping("/zouf")
	@ResponseBody
	public CommonResult zuofMpingtHyxx(@RequestParam(name = "id", required = true)int id,
											@RequestParam(name = "bz", required = true)int bz){
			int nun = 0;

			nun = mpingtHyxxService.zouf(id,bz);
			if (nun <= 0) {
			return CommonResult.exceptionResult("作废/恢复失败。");
			}
			return CommonResult.successResult("作废/恢复成功！");
			}

}
